<?php
/**
 * Klasa obsĹ‚ugi tablicy logow
 *
 */
class MfSqliteLogDAL extends DefaultDAL {


    protected static $objClassName;
    protected static $objClassTable;
    protected static $objClassTablePK;
    private static $optClass;

    public static function Save($dalObj) {
        if($dalObj->getObj()->GetId()=='-1') {
	    return self::DefaultInsert($dalObj);
	} else {
	    return self::DefaultUpdate($dalObj);
	}
    }

    public static function Insert($objDal) {
//        $db = new DBTemp();
//	if(!is_numeric($objDal->getObj()->getId()) || $objDal->getObj()->getId() == -1)
//	   $objDal->getObj()->SetId("NULL");
//
//	//$sql = "INSERT INTO " . $objDal->getObjClassTable() . " (time, type, description) VALUES (\"".$objDal->getObj()->getTime()."\", \"".$objDal->getObj()->getType()."\", \"".$objDal->getObj()->getMessage()."\")";
//$sql = "INSERT INTO " . $objDal->getObjClassTable() . " (".SQL::ToInsertFields($objDal->getObj()).") VALUES (" . SQL::ToInsertValues($objDal->getObj()).")";
//	//echo $sql;
//	$stmt = $db->execute($sql);
//
//	return $stmt->GetInsertionId();
return self::DefaultInsert($dalObj);
    }

    public static function Update($dalObj) {
        	$db = new DBTemp();

	$sql = "UPDATE " . $objDal->getObjClassTable() . " SET ". SQL::ToUpdateSet($objDal->getObj()) ." WHERE " . $objDal->getObjClassTablePK() ."=:*#1#* ";

	$stmt=$db->prepare($sql)
	    ->bindParam('*#1#*', $objDal->getObj()->GetId());

	$stmt->execute();

	return $objDal->getObj()->GetId();
    }

    public static function Delete($dalObj) {
        $db = new DBTemp();
	$sql = "DELETE FROM " . $dalObj->getObjClassTable() . " WHERE " . $dalObj->getObjClassTablePK() . "=:1";
	$stmt=$db->prepare($sql)
	    ->bindParam(1, $dalObj->getId())
	    ->execute();
    }

    public static function GetById($id) {
        return self::DefaultGetById(self::GetOptClass(), self::GetObjClassTable(), self::GetObjClassName(), self::GetObjClassTablePK(), $id);
    }


    public static function GetArrayObjAll() {

    }


    public static function GetResult($data,$queryFields = array(),$limit = 0, $sortBy = null,$count = null) {

		return self::DefaultGetResult(self::GetOptClass(), self::GetObjClassTable(), self::GetObjClassName(), $data, $queryFields, $limit, $sortBy, $count);

	}
	

	
	

	public static function GetObjClassName() {
        if(self::$objClassName != '') {
            $class = self::$objClassName;
        } else {
            $class = ereg_replace('DAL', '', __CLASS__);
        }

        return $class;
    }

    public static function GetOptClass() {
        if(self::$optClass!=null) {
            return self::$optClass;
        } else {
            return self::GetObjClassName();
        }
    }

    public static function GetObjClassTablePK() {
        if(self::$objClassTablePK != '') {
            $return = self::$objClassTablePK;
        } else {
            $class = self::GetObjClassName();
            $classObj = new $class();
            $return = $classObj->GetClassTablePK();
        }
        return $return;
    }

    public static function GetObjClassTable() {
        if(self::$objClassTable!='') {
            $return = self::$objClassTable;
        } else {
            $class = self::GetObjClassName();
            $classObj = new $class();
            $return = $classObj->GetTableName();
        }

        return $return;
    }

        public static function GetDalDataObj() {
	
	$dalData = new DalData();
	$dalData->setObjClassName(self::GetObjClassName());
	$dalData->setObjClassTable(self::GetObjClassTable());
	$dalData->setObjClassTablePK(self::GetObjClassTablePK());
	$dalData->setOptClass(self::GetOptClass());
	$dalData->setDatabaseType('dbTemp');

	return $dalData;
    }
}


?>